<!--
 * @Author: zhangjingyu
 * @Date: 2021-04-13 16:32:57
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-04-23 16:02:47
 * @FilePath: \vprisk10.14\src\views\ftpManage\pricingManage\sceneTask\sceneTask_viewResult.vue
 * @Description: 情景定价查看结果
-->
<template>
  <div>
    <span class="formTitle"><i class="vertical-bar"></i>{{ title }}</span>
    <el-form
      :model="searchForm"
      ref="searchForm"
      label-width="100px"
      label-position="left"
      size="mini"
    >
      <el-row :gutter="30">
        <el-col :span="6">
          <el-form-item label="任务名称：">
            <el-input v-model="taskName" disabled placeholder=""></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="定价编号：">
            <el-input v-model="pricingCode" disabled placeholder=""></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="情景：">
            <el-input v-model="sceneName" placeholder="" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="定价状态：">
            <auto-form
              v-model="pricingTaskStatus"
              elementType="4"
              disabled
              dimCode="ftp_pricing_task_status"
            ></auto-form>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="头寸数据表：" prop="positionTableFix">
            <el-select
              v-model="searchForm.positionTableFix"
              style="width:100%"
              placeholder="请选择"
            >
              <el-option
                v-for="item in positionOptions"
                :key="item.pdPostFix"
                :label="item.pdName"
                :value="item.pdPostFix"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="数据日期：" prop="dataDate">
            <el-date-picker
              v-model="searchForm.dataDate"
              type="date"
              style="width:100%"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="定价结果：" prop="status">
            <auto-form
              v-model="searchForm.status"
              elementType="4"
              dimCode="ftp_pricing_status"
            ></auto-form>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="账号：" prop="accountNum">
            <el-input
              v-model="searchForm.accountNum"
              maxlength="32"
              placeholder="请输入..."
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="机构：" prop="orgCode">
            <auto-form
              v-model="searchForm.orgCode"
              elementType="6"
              dimCode="cpm_dim_organ"
            ></auto-form>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="科目: " prop="subjectCode">
            <auto-form
              v-model="searchForm.subjectCode"
              elementType="6"
              dimCode="cpm_dim_subject"
            ></auto-form>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="产品：" prop="productCode">
            <auto-form
              v-model="searchForm.productCode"
              elementType="6"
              dimCode="cpm_dim_product"
            ></auto-form>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="行业：" prop="industryCode">
            <auto-form
              v-model="searchForm.industryCode"
              elementType="6"
              dimCode="cpm_dim_industry"
            ></auto-form>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="币种：" prop="currencyCode">
            <auto-form
              v-model="searchForm.currencyCode"
              elementType="8"
              dimCode="cpm_dim_currency"
            ></auto-form>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="起息日：" prop="orgDate">
            <el-date-picker
              v-model="searchForm.orgDate"
              type="date"
              style="width:100%"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="利率类型：" prop="rateTypeCd">
            <auto-form
              v-model="searchForm.rateTypeCd"
              elementType="4"
              dimCode="ftp_cp_rate_type_cd"
            ></auto-form>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="支付类型：" prop="payTypeCd">
            <auto-form
              v-model="searchForm.payTypeCd"
              elementType="4"
              dimCode="ftp_cp_pay_type_cd"
            ></auto-form>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="重定价频率：" prop="repriceFreq">
            <el-input
              v-model.trim="searchForm.repriceFreq"
              maxlength="40"
              style="display:inline-block;width:40%"
            ></el-input>
            <el-select
              v-model="searchForm.repriceFreqMult"
              placeholder="请选择"
              style="display:inline-block;width:60%"
            >
              <el-option
                v-for="item in dateOption"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="原始期限：" prop="orgTerm">
            <!-- <el-form-item label="指定期限：" prop="assignTerm"> -->
            <el-input
              v-model.trim="searchForm.orgTerm"
              maxlength="40"
              style="display:inline-block;width:40%"
            ></el-input>
            <el-select
              v-model="searchForm.orgTermMult"
              placeholder="请选择"
              style="display:inline-block;width:60%"
            >
              <el-option
                v-for="item in dateOption"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row style="text-align:center">
        <el-button @click="searchFunc()">查询</el-button>
        <el-button @click="reset()">重置</el-button>
      </el-row>
      <el-row class="container">
        <upper-template :searchIcon="false" :configIcon="false">
          <!-- 操作按钮区 -->
          <template slot="buttonArea" class="content-center" align="center">
            <el-button @click="expExcel()">导出</el-button>
            <el-button @click="usePricing()">执行定价</el-button>
            <el-button @click="toBackLast()">返回</el-button>
          </template>
        </upper-template>
      </el-row>
    </el-form>
    <el-table
      ref="multipleTable"
      :data="tableData"
      style="width: 100%"
      @row-click="rowClick"
    >
      <el-table-column
        width="55"
        type="selection"
        
      ></el-table-column>
      <el-table-column
        prop="ACCOUNTNUM"
        label="账号"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="DATADATE"
        label="数据日期"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="ORGCODE_DISP"
        label="机构"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="PRODUCTCODE_DISP"
        label="产品"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="SUBJECTCODE_DISP"
        label="科目"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="CURRENCYCODE_DISP"
        label="币种"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="CURBAL"
        label="当前余额"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="ORGDATE"
        label="起息日"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="INTRATE"
        label="对客利率"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="TRANSRATE"
        label="基础转移价格"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="FINALTRANSRATE"
        label="最终转移价格"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="COMPRICING"
        label="组合定价调整项"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="TRANSIE"
        label="转移收支"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="BREAKCHARGERESULT"
        label="BreakCharge结果"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="BREAKFUNDINGRESULT"
        label="BreakFunding结果"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="YEARPROFITLOSS"
        label="年度累计损益"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="PROFITANDLOSS"
        label="累计损益"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="HISTORYBALSUM"
        label="历史余额累计"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="ORGINTRATE"
        label="起息日的执行利率"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="ORGTRANSRATE"
        label="起息日的基础转移价格"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="ORGFINALTRANSRATE"
        label="起息日的最终转移价格"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="REPRICEINTRATE"
        label="上次重定价日执行利率"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="REPRICETRANSRATE"
        label="上次重定价日基础价格"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="REPRICEFINALTRANSRATE"
        label="上次重定价日最终价格"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="LASTREPRICEBAL"
        label="上次重定价余额"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="ORGBAL"
        label="原始余额"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="MATDATE"
        label="到期日"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="ORGTERM"
        label="原始期限"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="REPRICETYPECD"
        label="重定价类型代码"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="LASTREPRICEDATE"
        label="上次重定价日期"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="NEXTREPRICEDATE"
        label="下次重定价日期"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="REPRICEFREQ"
        label="重定价频率"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="PAYTYPECD_DISP"
        label="支付类型"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="LASTPAYDATE"
        label="上次支付日"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="NEXTPAYDATE"
        label="下次支付日"
        :show-overflow-tooltip="true"
      ></el-table-column>
    </el-table>
    <!-- 分页插件 -->
    <pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="searchForm.page"
      :page-size="searchForm.size"
      @refresh="searchFunc"
      :total="total"
    ></pagination>
  </div>
</template>

<script>
import autoForm from "@/components/ftp/autoForm.vue";
import { pricingTask } from "@/api/index";
import moment from "moment";
export default {
  components: { autoForm },
  props: {
    //选中的值
    baseData: {
      type: Object,
      default: () => ({})
    },
    title: String
  },

  data() {
    return {
      pricingCode: this.baseData.pricingCode,
      taskName: this.baseData.taskName,
    
      pricingTaskStatus: "",
      sceneName: "",
      searchForm: {
        page: 1,
        size: 15,
        sceneCode: "",
        dataDate: "",
        currencyCode:"CNY",
        pdName:this.baseData.pdName,
      },
      positionOptions: [{}],
      dateOption: [
        { value: "Y", label: "年" },
        { value: "M", label: "月" },
        { value: "D", label: "日" }
      ],
      tableData: [],
      total: 0 
    };
  },
  created() {
    this.toBlock();
  },
  methods: {
        expExcel(){
         //判断是根据条件查询  还是根据选择查询
          let data = {
        page: this.searchForm.page+1,
        size: this.searchForm.size,
        accountNum: this.searchForm.accountNum,
        currencyCode: this.searchForm.currencyCode,
        currencyCode_text: "",
        dataDate: this.searchForm.dataDate,
        industryCode: this.searchForm.industryCode,
        industryCode_text: "",
        order: "",
        orderBy: "",
        orgCode: this.searchForm.orgCode,
        orgCode_text: "",
        orgDate: this.searchForm.orgDate,
        orgTerm: this.searchForm.orgTermL+this.searchForm.orgTermdate,
        payTypeCd: this.searchForm.payTypeCd,
        positionResult: {},
        positionTableFix: this.searchForm.pdName,
        pricingStatus: this.searchForm.status,
        productCode: this.searchForm.productCode,
        productCode_text: "",
        rateTypeCd: this.searchForm.rateTypeCd,
        repriceFreq: this.searchForm.repriceFreqL+this.searchForm.date,
        subjectCode: this.searchForm.subjectCode,
        subjectCode_text: "",
      };
      console.log("导出的时候传递的参数"+JSON.stringify(data));
      pricingTask.expSceneResult(data).then(response => {
           console.log(response,"response");
        if (response.code == 500) {
          this.$message.error(response.message);
        } else if (response) {
          console.log(decodeURI(response.headers["content-disposition"]));
          var filename = decodeURI(
            response.headers["content-disposition"]
          ).split("=")[1];
          let contenttype =
            filename.substring(filename.lastIndexOf("."), filename.length) ===
            "xlsx"
              ? "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
              : "application/vnd.ms-excel;charset=utf-8";
          var blob = new Blob([response.data], {
            type: contenttype
          });
          if (window.navigator.msSaveOrOpenBlob) {
            navigator.msSaveBlob(blob, filename);
          } else {
            var downloadElement = document.createElement("a");
            var href = window.URL.createObjectURL(blob); //创建下载的链接
            downloadElement.href = href;
            downloadElement.download = filename; //下载后文件名
            document.body.appendChild(downloadElement);
            downloadElement.click(); //点击下载
            document.body.removeChild(downloadElement); //下载完成移除元素
            window.URL.revokeObjectURL(href); //释放掉blob对象
          }
          this.$message.success("导出成功");
        } else {
          this.$message.error(response.message || "获取失败");
        }
      });
    },
    toBlock() {
      let data = { pricingCode: this.baseData.pricingCode };
      pricingTask
        .toBlockSceneTask(`"${this.baseData.pricingCode}"`)
        .then(res => {
          if (res.code == 200) {
            this.positionOptions = res.datas.positions;
            this.searchForm.positionTableFix = this.positionOptions[0].pdPostFix;
            this.searchForm.dataDate = moment(
              res.datas.pricingRecord.dataDate
            ).format("YYYY-MM-DD");
            if (res.datas.task && res.datas.task.sceneManage) {
              this.sceneName = res.datas.task.sceneManage.sceneName;
              this.searchForm.sceneCode = res.datas.task.sceneManage.sceneCode;
              this.pricingTaskStatus = res.datas.task.status;
            }
            this.searchFunc();
          }
        });
    },
    reset() {
      console.log(this.baseData);
      for (const key in this.searchForm) {
        if (key != "page" && key != "size" && key != "dataDate"&&key!="positionTableFix"&&key!="currencyCode") {
          this.searchForm[key] = "";
        }
      }
    },
    exportResult() {},
    usePricing() {
      pricingTask
        .sceneTaskExcute({ taskCode: this.baseData.taskCode })
        .then(res => {
          if (res.code == 200&&res.data=='1') {
            this.$message.success("情景定价任务执行成功！");
          } else {
            this.$message.error(res.message);
          }
        });
    },
    //点击行选中
    rowClick(row) {
      if (this.$refs.multipleTable) {
        this.$refs.multipleTable.clearSelection();
      }
      this.$refs.multipleTable.toggleRowSelection(row, true);
    },
    searchFunc() {
      let data = { ...this.searchForm };
      for (const key in data) {
        if (data[key + "Mult"]) {
          data[key] += data[key + "Mult"];
          delete data[key + "Mult"];
        }
      }
      pricingTask.sceneResult(data).then(res => {
        if (res.code == 200) {
            this.tableData = res.datas.rows;
            this.total =res.datas.total
        }
      });
    },
    toBackLast() {
      this.$emit("toBackLast", "");
    },
    handleSizeChange(val) {
      this.searchForm.size = val;
      this.searchFunc();
      console.log(val, "每页数");
    },
    handleCurrentChange(val) {
      this.searchForm.page = val;
      this.searchFunc();
      console.log(val, "当前页");
    }
  }
};
</script>

<style lang="scss" scoped>
</style>